<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>错误的集合</title>
</head>
<body>
  <script>
    function fn(nums) {
      let res = []
      for (let i = 1; i <= nums.length; i++) {
        if (nums.indexOf(i) != nums.lastIndexOf(i)) {
          res.push(i)
        }
        if (nums.indexOf(i) == -1) res.push(i)
      }
      return res
    }
    console.log(fn([1, 2, 2, 4]))
  </script>
</body>
</html>